package com.itheima.web.controller;

import cn.hutool.core.util.StrUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.Comment;
import com.itheima.domain.mongo.Movement;
import com.itheima.domain.vo.MovementVo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.UserDetailVo;
import com.itheima.service.db.UserService;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Positive;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;
    /**
     * 用户列表数据
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/manage/users")
    public PageBeanVo findUsers(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize
    )  {
        return userManager.findUsers( pageNumber , pageSize );
    }


    /**
     * 用户详情
     * @return
     */
    @GetMapping("/manage/users/{id}")
    public UserDetailVo findUserById(
           @PathVariable("id") Long userId
    )  {
        return userManager.findUserById( userId );
    }


    /**
     * 视频列表
     * @return
     */
    @GetMapping("/manage/videos")
    public PageBeanVo findVideoByUserId(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize,
            Long uid
    )  {
        return userManager.findVideoByUserId( pageNumber , pageSize , uid  );
    }


    /**
     * 动态列表
     * @return
     */
    @GetMapping("/movement")
    public PageBeanVo findMovementList(
            @RequestParam(defaultValue = "1", name = "page") Integer pageNumber,
            @RequestParam(defaultValue = "10", name = "limit") Integer pageSize,
            Long uid,
            Long startDate,
            Long endDate
//            String state
    ) {

      /*  Integer stateInt = null;
        //前端有坑 没有传递state的时候 传入了 ''空串  state 需要判断 这是前端的小bug
        if (StrUtil.isNotEmpty(state)) {
            stateInt = Integer.valueOf(state);//转换成int
        }*/

        return userManager.findMovementList(pageNumber, pageSize, uid, startDate,endDate);
    }


    //动态详情
    @GetMapping("/manage/messages/{movementId}")
    public MovementVo findMovementList(

            @PathVariable String movementId
            )  {
        return userManager.findMovementById( movementId  );
    }

    //评论列表
    @GetMapping("/manage/messages/comments")
    public PageBeanVo findCommentList(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize,
            @RequestParam(name="messageID") String movementId
    )  {
        return userManager.findCommentList( movementId ,pageNumber , pageSize);
    }



}
